#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->label->setAlignment(Qt::AlignCenter);

    ui->lineEdit->setEchoMode(QLineEdit::Password);
    ui->lineEdit->setPlaceholderText("input your password");

    ui->lineEdit_2->setEchoMode(QLineEdit::Password);
    ui->lineEdit_2->setPlaceholderText("correct your password");
}

Widget::~Widget()
{
    delete ui;
}

void Widget::compare()
{
    const QString s1 = ui->lineEdit->text();
    const QString s2 = ui->lineEdit_2->text();
    if(s1.isEmpty()||s2.isEmpty())
        ui->label->setText("input your password");
    else if (s1 == s2)
        ui->label->setText("correspond");
    else
        ui->label->setText("uncorrespond");
}

void Widget::on_lineEdit_textEdited(const QString &arg1)
{
    (void)arg1;
    compare();
}
void Widget::on_lineEdit_2_textChanged(const QString &arg1)
{
    (void)arg1;
    compare();
}

void Widget::on_checkBox_toggled(bool checked)
{
    if(checked)
        ui->lineEdit->setEchoMode(QLineEdit::Normal);
    else
        ui->lineEdit->setEchoMode(QLineEdit::Password);
}


void Widget::on_checkBox_2_toggled(bool checked)
{
    if(checked)
        ui->lineEdit_2->setEchoMode(QLineEdit::Normal);
    else
        ui->lineEdit_2->setEchoMode(QLineEdit::Password);
}
